<?php

class Article_pro extends CI_Model{

    function __construct(){
        parent::__construct();
    }
    
    function add(){
       $name = $this->input->post("name"); 
       $description = $this->input->post("description");
       $dt = time();
       $now_date = date('Y-m-d H:i:s', $dt);
       $sql = "INSERT INTO article_pro (name, description, createdate) VALUES (?,?,?)";
       $data = $this->db->query($sql, array($name, $description, $now_date));
       return $data;
    }

    function list_properties(){
        $sql = "select name, description, createdate from article_pro order by createdate desc";
        $data = $this->db->query($sql);
        return $data;
    }

    function update(){
        $name = $this->input->post("name");
        $old_name = $this->input->post("old_name");
        $description = $this->input->post("description");
        /*
        $select_sql = "SELECT id FROM article_pro WHERE name=?";
        $id = $this->db->query($select_sql, $old_name);
        $id_result = $id->result();
        $id=$id_result[0]->id; 
         */
        $dt = time();
        $now_date = date('Y-m-d H:i:s', $dt);
        $sql = "UPDATE article_pro SET name=?, description=? WHERE name=?";
        $data = $this->db->query($sql, array($name, $description, $old_name));
        return $data;
    }
   
    function deletes(){
        $name = $this->input->post("name");
        $sql = "DELETE FROM article_pro WHERE name=?";
        $data = $this->db->query($sql, array($name));
        return $data;
    }

}
